<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>签到window</title>
  <link rel="stylesheet" text="text.css" href="../../css.api.css"/>

  <link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
  <link rel="stylesheet" type="text/css" href="../../css/base.css"/>
  <link rel="stylesheet" href="../../css/CFNetPP_Base.css">
  <style type="text/css">
    .historySign{
        clear: left;
        widows: 100%;
        height: 32px;
        font-size: 12px;
        color: #C1C1C1;
        padding-left: 10px;
        vertical-align: bottom;
        padding-top: 12px;
        background-color: #FFFFFF;
    }
  </style>
</head>
<body>
    <div class="base_style_color " id='BarAppearance' style="height: 22px;width: 100%"></div>
    <div class="base_navigation_bar base_style_color">
      <a class="base_left_item" href="#" onclick="closeWin()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
      <span>签到</span>
    </div>
  <div id="signSection" style="width: 100%;height: 255px;background-color: white;text-align: center;margin-top: 66px;">
        <div id="signName" style="width: 100%;height: 20px;padding-top: 25px;text-align: center;color:#666666;font-size: 14px;">
            暂无签到
        </div>
        <div id="signBorder" style="background-color: #999999;width: 150px;height: 150px;margin-top: 40px;margin-left: 30%;border-radius: 75px;text-align: center;position: relative;">

            <div style="background-color:white;width: 130px;height: 130px;border-radius: 65px;position: absolute;top:10px;left: 10px;text-align: center;" onclick="beginsign()">
                 <div id="signTime" style="color: #999999;font-size: 30px;position: absolute;top:45px;left: 0px;width:130px;text-align: center;font-weight: bold;">
                     16:45
                 </div>
                 <div id="signText" style="color: #999999;font-size: 16px;position: absolute;top:80px;left: 0px;width:130px;text-align: center;">
                     开始签到
                 </div>
            </div>
        </div>
    </div>
    
    <div class="historySign">历史签到记录</div>

</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/push.js"></script>
<script type="text/javascript">
    var signId = 0;
    var signName = "";
    apiready = function(){
       $('#signTime').html(getCurrentTime());
       //签到圆圈设置水平居中
       $('#signBorder').css('margin-left', (api.winWidth-150)/2); 
       
//     api.addEventListener({
//      name : 'signYesOrNoNotification'
//     }, function(ret, err) {
//      // alert(JSON.stringify(ret.value));
//      if (ret.value.id == 0) {
//                signId = 0;
//                signName = "";
//        haveNoSign();
//      } else {
//        signId = ret.value.id;
//        signName = ret.value.name;
//        haveSign();
//      }
//
//    });

        api.addEventListener({
        name : 'pushMessage_classroomMessage'
       }, function(ret, err) {
//      alert("消息推送"+ ret.value.jid+"=="+$api.getStorage('cfnetppjxid'));
       if(QD_TYPE == ret.value.type && $api.getStorage('cfnetppjxid') == ret.value.jid){
//     alert(11);
//      alert(ret.value.status);
          if(ret.value.status ==1){
	          signId = ret.value.id;
	          signName = ret.value.name;
	          haveSign();
          }else{
             haveNoSign();
              }
          }
            
       });

       setupSignedFrame();


       setInterval(function(){

           $('#signTime').html(getCurrentTime());

       },1000);
       
    }

    
    function haveSign () {
        $('#signName').html(signName);
            $('#signName').css("color","#222222");
            $('#signBorder').css("background-color","#18b4de");
            $('#signTime').html(getCurrentTime());
            $('#signTime').css("color","#222222");
            $('#signText').html("点击签到");
            $('#signText').css("color","#222222");
    }
    function haveNoSign () {
            $('#signName').html("暂无签到");
            $('#signName').css("color","#666666");
            $('#signBorder').css("background-color","#999999");
            $('#signTime').html(getCurrentTime());
            $('#signTime').css("color","#999999");
            $('#signText').html("开始签到");
            $('#signText').css("color","#999999");
    }
    function getCurrentTime () {
        var myDate = new Date();
        var hour = myDate.getHours();  
        var minutes = myDate.getMinutes();  
        if (parseInt(minutes) < 10) {
          minutes = '0'+minutes;

        }
        return hour + " : " + minutes;
    }
    function setupSignedFrame(){
      var headerY = 32 + 255;
      var y = $('#BarAppearance').height() + $('.base_navigation_bar').height()+headerY;
      var h = api.winHeight - y;
      var rect = {
        x : 0,
        y : y,
        w : 'auto',
        h : h
      }
      api.openFrame({
          name: 'Student_signedFrame',
          url: 'Student_signedFrame.html',
          rect: rect,
          hScrollBarEnabled : false,
          animation : {
          type:"none",                //动画类型（详见动画类型常量）
            subType:"from_right",       //动画子类型（详见动画子类型常量）
            duration:300                //动画过渡时间，默认300毫秒
        },
      });
    }
    function closeWin(){
      api.closeWin();
    }
    function beginsign () {

            if (signId != 0) {

            var url = url_stuSignYesNo;
            var params = {
                iid : signId,  //互动id
                uid : $api.getStorage('cfnetppuid'), //$api.getStorage('cfnetppuid'),  //学生id
                tid : 1,  //互动类型
            };
//         alert(JSON.stringify(params));
            showProgress();
            cfnetppPOST(url, params, true, function(data, status) {
//          alert(JSON.stringify(data));
                    hideProgress();
                    if (status == 'success') {
                        $('#noNet').hide();
                        if (data.code == 200) {
                            ShowToast(data.remind);
                            api.sendEvent({
                                name: 'signSuccess',
                            });
                        }else if(data.code == 108){  //已结束
                           ShowToast(data.message);
                        }else if(data.code == 107){  //不支持签到
                           ShowToast(data.message);
                        }else if(data.code == 109){  //签到失败
                           ShowToast(data.message);
                        }else if(data.code == 101){  //参数错误
                           ShowToast(data.message);
                        }else{                       //签到已结束
                            ShowToast(data.message);

                        }

                        changeSignShare();

                        haveNoSign();

//                      loadNewData();

                    } else {
                        // $('#noNet').show();
                    }
                });

        }else{
            ShowToast("老师还没有开始签到");

            changeSignShare();
            
            haveNoSign();
        }

        
    }
    //红点的隐藏
    function changeSignShare () {
        var jid = $api.getStorage('cfnetppjxid');
        //签到成功,赋值为没有签到
        $api.setStorage('cfnetppmessageclassroom' + jid + QD_TYPE, "0");
    }

</script>
</html>